<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登陆</title>
    <script src="./js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
    <style type="text/css">
        .login {
            font-size: 14px;
            box-sizing: border-box;
            white-space: normal;
            word-wrap: break-word;
            word-break: break-all;
            overflow: hidden;
            display: inline-block;
            width: 200px;
            height: 12.5rem;
            /* border: 10px solid red; */
        }
    </style>
</head>
<body style="display:inline-block;">
<div id="loginDiv" class="login">
    <h1>登陆</h1>
    <div>
        用户名：<input id="username" type="text" name="username" value="张三">
    </div>
    <div>
        密码：<input id="password" type="password" name="password" value="123">
    </div>
    <div>
        <!--        注意自动登录字段的 name 必须是 remember-me ：-->
        <label><input id="remember-me" type="checkbox" name="remember-me"/>自动登录</label>
        <input type="button" name="" id="login" value="立即登陆"/>
    </div>
</div>
<div id="" class="login">
    <input type="button" name="" id="select" value="查询"/>


</div>
<script type="text/javascript">
    $(function () {
        $("#login").click(function () {
            var url = "/login/login";
            var data = {
                username: $("#username").val(),
                password: $("#password").val(),
                "remember-me": $("#remember-me").val()
            }

            console.log(data)

            ajaxUtil(url, data, "ajaxresult")
        })

        $("#select").click(function () {
            var url = "/API/user/selectList";
            var data = {}

            console.log(data)

            ajaxUtil(url, data, "ajaxresult")
        })
    })

    function ajaxresult(e) {
        console.log(e)
    }

    function ajaxUtil(url, data, funName) {
        $.ajax({
            url: "http://127.0.0.1:8080" + url,
            type: 'POST',
            // contentType: "application/json;charset=UTF-8",
            data: data,
            //  默认情况下，标准的跨域请求是不会发送cookie的
            xhrFields: {
                withCredentials: true
            },
            //  默认情况下，标准的跨域请求是不会发送cookie的
            // beforeSend: function(xhr) {
            // 	xhr.withCredentials = true
            // },
            withCredentials: true,
            dataType: 'json',
            success: function (e) {
                var f = eval(funName);
                new f(e);
            }
        });
    }
</script>
</body>
</html>
